<template lang="pug">
    skin(@up="up",@down="down",@yes="yes",@back="back",@duringUp="up",@duringDown="down")
        div(class="flex-column h3")
            div(class="flex-column-item flex-center-center") 
              span -----方波大剂量----
            div(class="flex-column-item flex-center flex-3") 
                div(class="flex-row")
                  div(class="flex-row-item flex-4",style="height:100%")
                    div(class="flex-column")
                      div(class="flex-column-item flex-center",v-for="(menu,index) in currentPageMenus",:key="menu.id")
                        div(class="flex-row")
                          div(class="flex-row-item flex-7")
                            span(class="iconfont",:style="{'visibility': index == currentMenuIndex ? 'visible' : 'hidden'}") &#xe62c;
                            span {{menu.name}}
                          div(class="flex-row-item flex-1", v-if="!menu.isAction")
                            control-amount(v-model="currentPageMenus[index]",:working="menu.working",:ref="'ref'+menu.id")
                          div(class="flex-row-item flex-0", v-if="!menu.isAction")
                            span(style="font-size:0.6em") {{menu.unit}}

</template>

<script>
import MenuList from '@/mixins/MenuList'
export default{ 
  mixins: [MenuList],
  data() {
    return {
      menus: [
        {
          working: false,
          name: "方波剂量:",
          id: 0,
          value: { name: 0, value: 0 },
          unit: "u",
          max: 27,
          min: 2,
          increment: 0.1
        },
        {
          working: false,
          name: "输注时间:",
          id: 1,
          value: { name: 60, value: 60 },
          unit: "min",
          max: 240,
          min: 30,
          increment: 30
        },
        {
          working: false,
          name: window.dose.squareWare.tasking
            ? "取消方波输注"
            : "开始方波输注",
          id: 2,
          isAction: true
        }
      ],
      page: { maxResultCount: 3},
    };
  },
  methods: {
    up() {
      if (this.currentMenu.working) {
        this.$refs['ref'+this.currentMenu.id][0].up();
        return;
      } 

      this.activeId --;
      
    },
    down() {
      if (this.currentMenu.working) {
        this.$refs['ref'+this.currentMenu.id][0].down();
        return;
      } 
      
      this.activeId ++;
    },

    back() {
      if (this.currentMenu.working) {
        this.currentMenu.working = false;
      }
      else {
        this.$router.push("/large-dose/menu?index=1");
      }
    },
    yes() {
      if (this.currentMenu.isAction) {
        if (this.menus[0].value.value <= 0) return;
        if (!window.dose.squareWare.tasking) {
          window.dose.squareWare.amount = this.menus[0].value.value;
          window.dose.squareWare.minutes = this.menus[1].value.value;
          window.dose.squareWare.createAt = new Date();
          window.dose.records.push({
            date: new Date(),
            amount: window.dose.squareWare.amount,
            type: "S"
          });
        }
        window.dose.squareWare.tasking = !window.dose.squareWare.tasking;
        this.$router.push("/");
      } else {
        this.currentMenu.working = !this.currentMenu.working;
      }
    }
  },
  created() {
    this.menus[0].value = {
      name: window.dose.squareWare.tasking ? window.dose.squareWare.amount : 0,
      value: window.dose.squareWare.tasking ? window.dose.squareWare.amount : 0
    };
    this.menus[1].value = {
      name: window.dose.squareWare.tasking
        ? window.dose.squareWare.minutes
        : 60,
      value: window.dose.squareWare.tasking
        ? window.dose.squareWare.minutes
        : 60
    };
    this.active = this.menus[0];
  }
};
</script>

<style lang="less">
</style>
